package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.ClassesService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 班级信息 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-02-10
 */
@RestController
@RequestMapping("/classes")
public class ClassesController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ClassesService classesServiceImpl;

    /**
     * 查询无数权限的班级
     * @param request
     * @param gradeId 年级id
     * @return
     */
    @RequestMapping("/findNoClass")
    private Result findNoClass(RequestParameterWrapper request,
                               @RequestParam(value = "gradeId",required = false)Integer gradeId){
        logger.info("查询无数据权限的班级信息");
        return classesServiceImpl.findNoClass(gradeId);
}

    /**
     * 查询无数据权限的年级信息
     * @param request
     * @return
     */
    @RequestMapping("/findNoGrade")
        public Result findNoGrade(RequestParameterWrapper request){
        logger.info("查询无数据权限的年级信息");
        //学校id
        String schoolId = request.getParam("schoolId");
        return classesServiceImpl.findNoGrade(schoolId);
    }

    /**
     * 查询有数据权限的班级信息
     * @param request
     * @param gradeId  年级id
     * @return
     */
    @RequestMapping("/findClasses")
    public Result findClasses(RequestParameterWrapper request,
                              @RequestParam(value = "gradeId",required = false)Integer gradeId){
        logger.info("查询有数据权限的班级信息");
        //获取学校id
        String schoolId  = request.getParam("schoolId");
        //教师id
        String  teacherId = request.getParam("teacherId");
        //获取管理员
        String admin = request.getParam("admin");
        //判断是否是管理员
        if("0".equals(admin)){
            return classesServiceImpl.findNoClass(gradeId);
        }else{
            return classesServiceImpl.findClasses(schoolId,teacherId,gradeId);
        }
    }

    /**
     * 查询有数据权限的年级
     * @param request
     * @return
     */
    @RequestMapping("/findGrade")
    public Result findGrade(RequestParameterWrapper request){
        logger.info("查询有数据权限的年级级信息");
        //学校id
        String schoolId = request.getParam("schoolId");
        //教师id
        String  teacherId = request.getParam("teacherId");

        //获取管理员
        String admin = request.getParam("admin");
        //判断是否是管理员
        if("0".equals(admin)){
            return classesServiceImpl.findNoGrade(schoolId);
        }else {
            return classesServiceImpl.findGrade(schoolId,teacherId);
        }

    }

}

